package com.control.qct.businesssteward.utils;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.control.qct.businesssteward.R;

/**
 * Created by Administrator on 2017/12/12 0012.
 */

public class PopUtils {
    private static PopUtils mPopUtils;
    public static PopUtils getInstance(){
        if (mPopUtils == null){
            mPopUtils = new PopUtils();
        }
        return mPopUtils;
    }

    /**
     * 底部弹窗
     * @param activity
     * @param view
     * @return
     */
    public PopupWindow getBottomPop(final Activity activity, View view){
        final PopupWindow pop = new PopupWindow(activity);
        pop.setContentView(view);
        //设置PopupWindow弹出窗体的宽
        pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体的高
        pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置PopupWindow弹出窗体可点击
        pop.setFocusable(true);
        //设置PopupWindow弹出窗体动画效果
        pop.setAnimationStyle(R.style.Animation);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xff000000);
        //设置PopupWindow弹出窗体的背景
        pop.setBackgroundDrawable(dw);
        // 设置背景颜色变暗
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        lp.alpha = 0.7f;
        activity.getWindow().setAttributes(lp);
        pop.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
                lp.alpha = 1f;
                activity.getWindow().setAttributes(lp);
            }
        });
        return pop;
    }
}
